package persistencia.HSQL;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import persistencia.DAOS.RequisitoCursoDAO;

public class HSQLRequisitoCursoDAO implements RequisitoCursoDAO{
	private static Connection connection;
	
	public static void conectar(){
		connection = null;
		try {
			Class.forName("org.hsqldb.jdbcDriver");
			connection = DriverManager.getConnection("jdbc:hsqldb:hsql://localhost/", "sa", ""); 	
		}
		
		catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}
	
	public static void desconectar(){
		try {
			connection.close();
		} catch (SQLException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	public ArrayList<Integer> cargarRequisitoCurso(Integer in) {
		ArrayList<Integer> lista = null;
		conectar();	
		
		try {
			Statement stm = connection.createStatement();
			ResultSet rs = stm.executeQuery("SELECT idCurso FROM Requisito_Curso WHERE idEmpleo = " + in);
			
			while(rs.next()){
				if(lista == null)
					lista = new ArrayList<Integer>();
				
				lista.add(rs.getInt("idCurso"));
			}
				
			
			desconectar();
			stm.close();
		}
		
		catch (SQLException e) {
			e.printStackTrace();
		}
	
		return lista;
	}
}
